/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.cleaner;

import cz.mzk.rehan.commons.DatastreamId;
import cz.mzk.kramerius.fedoraaccess.FedoraConnector;
import cz.mzk.rehan.commons.Dom4jUtils;
import java.io.File;
import java.io.FileNotFoundException;
import org.dom4j.Document;
import org.dom4j.DocumentException;

/**
 *
 * @author Martin Řehánek (rehan at mzk.cz)
 */
public class RelsExtUpdater {

    private final FedoraConnector con;

    public RelsExtUpdater(FedoraConnector con) {
        this.con = con;
    }

    public void saveRelsExtToFile(String objectPid, File outFile) {
        Document doc = con.getDatastreamDissemination(objectPid, DatastreamId.RELS_EXT);
        Dom4jUtils.saveDocument(doc, outFile);
    }

    public void updateRelsExtFromFile(String objectPid, File inFile) throws FileNotFoundException, DocumentException {
        Document doc = Dom4jUtils.loadDocument(inFile,false);
        con.updateDatastreamInlineContent(objectPid, DatastreamId.DC, doc);
    }
}
